/*
 *  $Id: StormDemon.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Air.Creatures {
    public class StormDemon: DemonCreatureCard {
        public StormDemon(): base("001_a_c_storm_demon") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Air;
            Value = 100;
            Damage = 4;
            Health = 5;
			AddManaCost(ElementType.Air, 4);
			AddManaCost(ElementType.Darkness, 2);
            PactValue = 2;
        }

        public override void SetNaturalAffects(ICollector<Affect> affects) {
            affects.Add<Affects.FlightBlock>();
            affects.Add(new Affects.Immune(DamageType.MagicAttack));
            affects.Add<StormDemonAffect>();
        }

        public override void ExecutePact(Player owner) {
            DoStorm(owner);
            DoStorm(owner.Enemy);
        }
        private void DoStorm(Player player) {
            foreach (Creature cr in player.GetCreatures()) if (cr.CanFly) {
                if (cr.Disabled)
                    cr.AddAffect<DemonicStorm>();
                else
                    cr.DamageBy(new DamageInfo(DamageType.MagicAttack, 1));
            }
        }

        private class StormDemonAffect: Affect {
            private static readonly Languages.CardPhrase<StormDemon> Action = new Languages.CardPhrase<StormDemon>("affect.flight.action");

            public override string Id {
                get { return AffectManager.GetCardId<StormDemon>("flight"); }
            }

            public override void SetAffect() {
                base.SetAffect();
                GlobalSummary.OnLandSummon += DoSummon;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                GlobalSummary.OnLandSummon -= DoSummon;
            }

            private void DoSummon(Land land) {
                if (land.Card.Element == ElementType.Air && !Owner.HasAffect<StormDemonFlight>()) {
                    Owner.AddAffect<StormDemonFlight>();
                    Game.Current.Log.Add(Action.Phrase, Owner);
                }
            }
        }

        private class StormDemonFlight: SpellAffect<StormDemon> {
            public StormDemonFlight(): base(true) {
                DefaultName = true;
                DefaultDescription = true;
                Add(new TimeAffect(4, new Affects.Flight()));
            }

            public override string Id {
                get { return AffectManager.GetCardId<StormDemon>("flight"); }
            }
        }

        private class DemonicStorm: SpellAffect<StormDemon> {
            public DemonicStorm(): base(true) {
                DefaultName = true;
                DefaultDescription = true;
                Add(new Affects.Idler());
            }

            public override string Id {
                get { return AffectManager.GetCardId<StormDemon>("storm"); }
            }
        }
    }
}
